package com.jeesite.modules.digitalize.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeesite.modules.digitalize.entity.dto.DigitalizeTaskAuditDTO;
import com.jeesite.modules.digitalize.entity.dto.DigitalizeTaskDTO;
import com.jeesite.modules.digitalize.entity.dto.DigitalizeTaskQuery;
import com.jeesite.modules.digitalize.entity.dto.system.reviewproces.DeleteIdListDTO;
import com.jeesite.modules.digitalize.entity.vo.DigitalizeTaskInfoVO;
import com.jeesite.modules.digitalize.entity.vo.DigitalizeTaskVO;
import com.jeesite.modules.digitalize.service.DigitalizeMessageService;
import com.jeesite.modules.digitalize.service.DigitalizeTaskService;
import com.jeesite.modules.digitalize.util.response.ResultVo;
import com.jeesite.modules.sys.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 数字-任务模块
 *
 * @author makejava
 * @since 2023-11-11 17:05:12
 */
@RestController
@Api(tags = "数字-任务模块")
@RequestMapping(value = "${adminPath}/digitalize/task")
public class DigitalizeTaskController {
    /**
     * 服务对象
     */
    @Resource
    private DigitalizeTaskService digitalizeTaskService;
    @Resource
    private DigitalizeMessageService digitalizeMessageService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @ApiOperation("列表")
    @GetMapping("/pageList")
    public ResultVo<Page<DigitalizeTaskVO>> pageList(@Validated DigitalizeTaskQuery query) {
        return ResultVo.success(this.digitalizeTaskService.pageList(query));
    }

    /**
     * 查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiModelProperty("查询单条数据")
    @GetMapping("/info/{id}")
    public ResultVo<DigitalizeTaskInfoVO> selectOne(@PathVariable Long id) {
        return this.digitalizeTaskService.getInfo(id);
    }

    /**
     * 新增或保存
     *
     * @return 新增结果
     */
    @ApiModelProperty("新增或保存")
    @PostMapping("/saveOrUpdate")
    public ResultVo<DigitalizeTaskVO> saveOrUpdate(@RequestBody @Validated DigitalizeTaskDTO dto) {
        return this.digitalizeTaskService.saveOrUpdate(dto);
    }


    @PostMapping("/delete")
    public ResultVo deleteList(@RequestBody @Validated DeleteIdListDTO dto) {
        return ResultVo.success(this.digitalizeTaskService.delete(dto.getIdList()));
    }

    /**
     * 任务审核
     *
     * @return 新增结果
     */
    @ApiModelProperty("任务审核")
    @PostMapping("/audit")
    public ResultVo audit(@RequestBody DigitalizeTaskAuditDTO dto) {
        return this.digitalizeTaskService.audit(dto);
    }

    @ApiOperation("任务归档")
    @ApiImplicitParam(name = "id", value = "任务id", required = true, dataType = "Long", paramType = "path")
    @PostMapping("/archive/{id}")
    public ResultVo archive(@PathVariable Long id) {
        return this.digitalizeTaskService.archive(id, UserUtils.getUser());
    }
}

